package com.example.medical.controller;

import com.example.medical.domain.Equipment;
import com.example.medical.service.EquipmentService;
import com.example.medical.util.AjaxResuit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
@RestController
@RequestMapping("/equipment")
@Api(tags = "器械管理（0525王婕）")
public class EquipmentController {

    @Autowired
    EquipmentService service;

    // 获取所有设备列表
    @GetMapping("/getEquipmentListAll")
    @ApiOperation(value = "获取器械列表")
    public AjaxResuit getEquipmentListAll() {
        System.out.println(service.selectAll());
        return AjaxResuit.success(service.selectAll());
    }
    // 根据设备id查询设备信息
    @GetMapping("/getEquipmentById")
    @ApiOperation(value = "根据id查询器械信息")
    public AjaxResuit getEquipmentById(int id) {
        System.out.println(service.selectById(id));
        return AjaxResuit.success(service.selectById(id));
    }

    // 新增设备
    @PostMapping("/addEquipment")
    @ApiOperation(value = "新增器械")
    public AjaxResuit addEquipment(@RequestBody Equipment equipment) {
        return AjaxResuit.success(service.saveEquipment(equipment));
    }
    // 设备登录（这里假设存在设备相关登录逻辑，比如远程控制设备等情况需登录验证，可按实际调整）
    @PostMapping("/EquipmentLogin")
    @ApiOperation(value = "器械登录")
    public AjaxResuit EquipmentLogin(Equipment equipment) {
        return AjaxResuit.success(service.checkEquipment(equipment));
    }
    // 更新器械信息接口，接收更新后的器械对象，调用Service层方法进行更新操作并返回相应结果
    @PutMapping("/updateEquipment")
    @ApiOperation(value = "更新器械信息")
    public AjaxResuit updateEquipment(@RequestBody Equipment equipment) {
        int result = service.updateEquipment(equipment);
        if (result > 0) {
            return AjaxResuit.success("器械信息更新成功");
        } else {
            return AjaxResuit.error("器械信息更新失败");
        }
    }

    // 删除器械接口，根据传入的器械id调用Service层方法删除对应器械，并返回相应结果
    @DeleteMapping("/deleteEquipment")
    @ApiOperation(value = "删除器械")
    public AjaxResuit deleteEquipment(int id) {
        int result = service.deleteEquipment(id);
        if (result > 0) {
            return AjaxResuit.success("器械删除成功");
        } else {
            return AjaxResuit.error("器械删除失败");
        }
    }
}
